package com.woniu.server.controller;

import com.woniu.common.utils.ResponseData;
import com.woniu.server.dto.ProductInfoDto;
import com.woniu.server.pojo.ProjectProduct;
import com.woniu.server.service.ProjectProductService;
import com.woniu.server.service.ProjectStorageService;
import com.woniu.server.service.impl.ProjectDetailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author hht
 * @Date Create by 2024/11/23 15:28
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProjectProductService projectProductService;
    @Autowired
    private ProjectStorageService projectStorageService;

    @GetMapping("/queryAllProduct")
    public ResponseData<?> queryAllProduct() {
        return projectProductService.queryAllProduct();
    }

    @GetMapping("/queryProductByCode")
    public ResponseData<?> queryProductByCode(@RequestParam("productCode") String productCode) {
        return projectProductService.queryProductByCode(productCode);
    }

    @GetMapping("/reduceStock")
    public ResponseData<?> reduceStock(@RequestParam("productCode") String productCode,
                                        @RequestParam("reduceNum") Integer reduceNum) {
        return projectStorageService.reduceStock(productCode,reduceNum);
    }

    @GetMapping("/rollbackStock")
    public ResponseData<?> rollbackStock(@RequestParam("productCode") String productCode,
                                       @RequestParam("reduceNum") Integer reduceNum) {
        return projectStorageService.rollbackStock(productCode,reduceNum);
    }

    @GetMapping("/queryAllProductList")
    public List<ProductInfoDto> queryAllProductList() {
        return projectProductService.queryAllProductList();
    }
}
